
//发送同步请求功能
function amSend(zUrl,fProcessReq,zPost){

if((!zUrl)||(zUrl.length<10)){alert("amSend 没有URL");return false}
if(typeof(fProcessReq)!="function"){alert("amSend 没有返还函数");return false;}
var	aArgs=new Array();
aArgs.zUrl=zUrl;
aArgs.vOk=fProcessReq;
aArgs.zPost=zPost;
if(cAm.mzUrl){
	if(cAm.mzUrl==aArgs.zUrl)return weMsg("★☆不能多次提交同一个请求!<br>请稍等...",false);
	cAm.maStack.push(aArgs);return true;
}
cAm.mvWait();
return	cAm.mvAsk(aArgs);
}

//处理返回信息功能
function okAns(){return cAm.mRes()};

//类定义
function CAm(){
this.mhReq	=null;	//Ajax request handler
this.mvOk	=null;	//Request ok, response method
this.mzUrl	=null;	//request URL
this.maStack=new Array();
}
CAm.prototype.mvIsFinished=function(){return this.mzUrl==null;}
CAm.prototype.mvWait=function(){
for(var i=0;i<frames.length;i++){
if(typeof(frames[i])!="object"){window.status="设置执行图标 frames["+i+"] 不是对象";continue;}
if(typeof(frames[i].document)=="unknown"){alert("装载 frames["+i+"] 失败");continue;}
var oDoc=frames[i].document;
if(oDoc.readyState!="complete")continue;
var oSty=oDoc.body.style;
if(oSty.cursor=="wait")continue;
oSty.cursor="wait";
}
return	weMsg("★☆作业处理中<br>请耐心等待!");
}
CAm.prototype.mvAuto=function(){
for(var i=0;i<frames.length;i++){
if(typeof(frames[i])!="object"){window.status="恢复图标 frames["+i+"] 不是对象";continue;}
if(typeof(frames[i].document)=="unknown"){alert("装载 frames["+i+"] 失败");continue;}
var oDoc=frames[i].document;
if(oDoc.readyState!="complete")continue;
var oSty=oDoc.body.style;
if(oSty.cursor=="auto")continue;
oSty.cursor="auto";
}
return	cMsg.mvShut();
}
//处理返回信息方法
CAm.prototype.mRes=function(){
if(this.mhReq.readyState!=4){return false;}//对象执行状态未完成
if(this.mhReq.status==200){
	if(typeof(this.mvOk)!="function"){alter("回调函数不是 function:"+typeof(this.mvOk));}
	else{
		try{this.mvOk(this.mhReq.responseText);}
		catch(e){alert("回调函数执行失败:"+e.message+"["+(e.number & 0xFFFF)+"]"+e.name);}
	}
}//信息已经成功返回，返回处理信息
else{weMsg("您所请求的页面有异常"+this.mhReq.status);}
if(this.maStack.length==0){this.mzUrl=null;return this.mvAuto();}//同步队列，异步处理
return this.mvAsk(this.maStack.shift());
}
//ask method for inside use by mSend
CAm.prototype.mvAsk=function(aArgs){
this.mzUrl=aArgs.zUrl;
this.mvOk=aArgs.vOk;
if(window.XMLHttpRequest){		//Mozilla 浏览器
	this.mhReq=new XMLHttpRequest();
	if(this.mhReq.overrideMimeType){this.mhReq.overrideMimeType("text/xml");}//设置 MiME 类别
}
else if(window.ActiveXObject){	// IE浏览器
 try{this.mhReq=new ActiveXObject("Microsoft.XMLHTTP");
 }catch(e){
	try{this.mhReq=new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){alert("浏览器不能创建XMLHttpRequest对象实例."+e);return false;}
 }
}
this.mhReq.onreadystatechange=okAns;
if(aArgs.zPost){
	//alert("zPost");
	//alert(aArgs.zPost);

//	this.mhReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	this.mhReq.open("POST",aArgs.zUrl,true);
	this.mhReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	return this.mhReq.send(aArgs.zPost);
}
else{
	this.mhReq.open("GET",aArgs.zUrl,true);
	return this.mhReq.send(null);
	}
}

//Create instance
var cAm=new CAm();
